Namespace Base
    ''' <summary>
    ''' This class is use to populate the context menu of our Grid, it's an item of the menu.
    ''' </summary>
    ''' <remarks>
    ''' indentureLevel is a string parameters. it can also represent a smallint for the tree level
    ''' design Pattern does not recommand tree level to permit future development of dynamic node Grouping. 
    ''' In this matter the node level of the tree can change therefor not represent the initial node nature.</remarks>
    Public Class ActionOption

        Public Sub New()
        End Sub



        ''' <summary>
        ''' For Parent Action definition
        ''' </summary>
        ''' <param name="optionGroup"></param>
        ''' <param name="optionName"></param>
        ''' <param name="optionTitle"></param>
        ''' <param name="enabled"></param>
        ''' <param name="visible"></param>
        ''' <param name="indentureLevel"></param>
        ''' <remarks>
        ''' indentureLevel is a string parameters. it can also represent a smallint for the tree level
        ''' design Pattern does not recommand tree level to permit future development of dynamic node Grouping. 
        ''' In this matter the node level of the tree can change therefor not represent the initial node nature.</remarks>
        Public Sub New(ByVal optionGroup As String, ByVal optionName As String, ByVal optionTitle As String, ByVal enabled As Boolean, ByVal visible As Boolean, Optional ByVal indentureLevel As String = Nothing)
            Me.OptionGroup = optionGroup
            Me.OptionName = optionName
            Me.OptionTitle = optionTitle
            Me.Enabled = enabled
            Me.Visible = visible
            Me.IndentLevelReference = indentureLevel
            _withHandler = False
        End Sub

        ''' <summary>
        ''' For Main Action option with EventHandler . Commun usage
        ''' </summary>
        ''' <param name="optionGroup"></param>
        ''' <param name="optionName"></param>
        ''' <param name="optionTitle"></param>
        ''' <param name="eventHandler"></param>
        ''' <param name="enabled"></param>
        ''' <param name="visible"></param>
        ''' <param name="indentureLevel"></param>
        ''' <remarks>
        ''' indentureLevel is a string parameters. it can also represent a smallint for the tree level
        ''' design Pattern does not recommand tree level to permit future development of dynamic node Grouping. 
        ''' In this matter the node level of the tree can change therefor not represent the initial node nature.</remarks>
        Public Sub New(ByVal optionGroup As String, ByVal optionName As String, ByVal optionTitle As String, ByVal eventHandler As EventHandler, ByVal enabled As Boolean, ByVal visible As Boolean, Optional ByVal indentureLevel As String = Nothing)
            Me.OptionGroup = optionGroup
            Me.OptionName = optionName
            Me.OptionTitle = optionTitle
            Me.EventHandler = eventHandler
            Me.Enabled = enabled
            Me.Visible = visible
            Me.IndentLevelReference = indentureLevel
            _withHandler = True
        End Sub

        ''' <summary>
        ''' For Sub actionDefinition with EventHandler
        ''' </summary>
        ''' <param name="optionGroup"></param>
        ''' <param name="optionName"></param>
        ''' <param name="optionTitle"></param>
        ''' <param name="eventHandler"></param>
        ''' <param name="enabled"></param>
        ''' <param name="visible"></param>
        ''' <param name="parentOption"></param>
        ''' <param name="indentureLevel"></param>
        ''' <remarks></remarks>
        Public Sub New(ByVal optionGroup As String, ByVal optionName As String, ByVal optionTitle As String, ByVal eventHandler As EventHandler, ByVal enabled As Boolean, ByVal visible As Boolean, ByVal parentOption As ActionOption, Optional ByVal indentureLevel As String = Nothing)
            Me.OptionGroup = optionGroup
            Me.OptionName = optionName
            Me.OptionTitle = optionTitle
            Me.EventHandler = eventHandler
            Me.Enabled = enabled
            Me.Visible = visible
            Me.IndentLevelReference = indentureLevel
            _withHandler = True
            Me.ParentActionOption = parentOption
        End Sub




        Private _withHandler As Boolean = True

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Public ReadOnly Property WithHandler As Boolean
            Get
                WithHandler = _withHandler
            End Get
        End Property

        ''' <summary>
        ''' QueryName is use to hide or show the Option depending on the QueryName of the GridExt
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks>In some control it Containe the Level number of the GridExtPL.</remarks>
        Public Property IndentLevelReference As String
        ''' <summary>
        ''' Procedure that will be call when the option is selected
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property EventHandler() As EventHandler
        ''' <summary>
        ''' Option is Enabled or Disable in the menu
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Visible() As Boolean
        ''' <summary>
        ''' Option is Visible or not in the menu
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Enabled() As Boolean
        ''' <summary>
        ''' Name of the Option Group
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks>Use to regroup in section</remarks>
        Public Property OptionGroup() As String
        ''' <summary>
        ''' Name of the option/Command
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property OptionName() As String
        ''' <summary>
        ''' Title display for the menu
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property OptionTitle() As String


        ''' <summary>
        ''' 
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property ParentActionOption As ActionOption
    End Class
    ''' <summary>
    ''' This collection is use to populate the context menu. GridExtPL is one of the control who use it.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class ActionOptionList
        Inherits List(Of ActionOption)

        Public Sub ApplySecurity()
            Dim aControlprops As DataView

            For Each action As ActionOption In Me
                'Set 
                aControlprops = (From oControl In AppManager.DataSubjectAccess.AsEnumerable() _
                                 Where oControl.Field(Of String)("ControlCD") = action.OptionName _
                                 And oControl.Field(Of String)("Class") = "ACT" _
                                 And oControl.Field(Of String)("Property") = "Visible"
                                 Select oControl).AsDataView()

                If aControlprops.Count = 1 Then
                    If AppManager.ApplicationOption.DescriptionColumnIndex = 2 Then
                        action.OptionTitle = aControlprops.Item(0).Row("ControlDescr_PRM").ToString()
                    ElseIf AppManager.ApplicationOption.DescriptionColumnIndex = 3 Then
                        action.OptionTitle = aControlprops.Item(0).Row("ControlDescr_ALT").ToString()
                    End If
                    '
                    If action.OptionTitle.IndexOf("<ExportToMasterDB>") > 0 Then
                        action.OptionTitle = action.OptionTitle.Replace("<ExportToMasterDB>", AppManager.ExportToMasterDB)
                    End If

                    action.Visible = CBool(aControlprops.Item(0).Row("Value").ToString())
                End If


                aControlprops = (From oControl In AppManager.DataSubjectAccess.AsEnumerable() _
                                Where oControl.Field(Of String)("ControlCD") = action.OptionName _
                                And oControl.Field(Of String)("Class") = "ACT" _
                                And oControl.Field(Of String)("Property") = "Enabled"
                                Select oControl).AsDataView()

                If aControlprops.Count = 1 Then
                    action.Enabled = CBool(aControlprops.Item(0).Row("Value").ToString())
                End If

            Next
        End Sub

        Public Function GetActionOptionByTitle(ByVal title As String) As ActionOption
            For Each anActionOption As ActionOption In Me
                If anActionOption.OptionTitle = title Then Return anActionOption
            Next

            Return Nothing
        End Function

    End Class

End Namespace
